from sympy import *

x=Symbol('x')
xn=Symbol('xn')
h=Symbol('h')

p1=2*(x-xn)/h*(x-xn)/h-3*(x-xn)/h+1
p2=2*(x-xn)/h*(x-xn)/h-(x-xn)/h
p3=-4*(x-xn)/h*(x-xn)/h+4*(x-xn)/h

print("First order derivative of p1,p2,p3")
print(simplify(p1.diff(x,1)))
print(simplify(p2.diff(x,1)))
print(simplify(p3.diff(x,1)))

print("Second order derivative of p1,p2,p3")
print(p1.diff(x,2))
print(p2.diff(x,2))
print(p3.diff(x,2))

print("Third order derivative of p1,p2,p3")
print(p1.diff(x,3))
print(p2.diff(x,3))
print(p3.diff(x,3))



